package com.kds.smarthome.mapper;

import com.kds.smarthome.entity.User;
import com.kds.smarthome.entity.Building;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper {
    List<User> findAll(Map<String, Object> params);
    User findById(Long id);
    User findByUsername(String username);
    List<String> findUserRoles(Long userId);
    void insertUser(User user);
    void updateUser(User user);
    void deleteUser(Long id);
    void insertUserRole(@Param("userId") Long userId, @Param("roleName") String roleName);
    void deleteUserRoles(Long userId);
    /**
     * 仅查询用户名和密码用于登录验证
     */
    User findByUsernameForAuth(String username);
    long count(Map<String, Object> params);
    
    // 新增方法
    void updatePassword(@Param("id") Long id, @Param("password") String password);
    void updateLockStatus(@Param("id") Long id, @Param("locked") Boolean locked);
    void updateEnabledStatus(@Param("id") Long id, @Param("enabled") Boolean enabled);
    
    // 用户建筑管理相关方法
    List<Building> findBuildingsByUsername(String username);
    void assignBuildingToUser(@Param("username") String username, @Param("buildingCode") String buildingCode);
    void removeBuildingFromUser(@Param("username") String username, @Param("buildingCode") String buildingCode);
    void removeAllBuildingsFromUser(String username);
    List<String> findBuildingCodesByUsername(String username);
    boolean checkUserBuildingExists(@Param("username") String username, @Param("buildingCode") String buildingCode);
}
